# 函数实例
import threading
import time


# 为线程定义一个函数
def print_time(threadName, delay):
    count = 0
    while count < 5:
        time.sleep(delay)
        count += 1
        print("%s: %s" % (threadName, time.ctime(time.time())))


# 创建两个线程
try:
    print("创建线程")
    obj1 = threading.Thread(target=print_time, args=("Thread-1", 1,))
    obj2 = threading.Thread(target=print_time, args=("Thread-2", 2,))
    obj1.start()  # 启动线程活动
    obj2.start()
    obj1.join()  # 等待至线程中止。这阻塞调用线程直至线程的join()方法被调用中止-正常退出或者抛出未处理的异常-或者是可选的超时发生。
    obj2.join()
    print("退出主线程")
except:
    print("Error: unable to start thread")

while 1:
    pass